package org.kazuhiko.rpg.display;

import java.io.IOException;

import org.kazuhiko.rpg.client.Client;
import org.kazuhiko.rpg.core.Game;
import org.lwjgl.LWJGLException;
import org.lwjgl.opengl.Display;
import org.lwjgl.opengl.DisplayMode;

public class GameScreen
{
	//The display width
	public static final int DISPLAY_WIDHT = 1200;
	//The display height
	public static final int DISPLAY_HEIGHT = 800;
	
	//The title of the frame
	public static final String GAME_NAME = "Java RPG.";
	
	//If the frame is in full screen
	private static boolean fullScreen;
	
	//The vsync
	private static boolean vSync;
	
	private static Client client;
	
	//Start up 
	public static void main( String[] args )
	{
		init();
	}
	
	public static Client getClient()
	{
		if( client == null )
		{
			try
			{
				client = new Client();
				client.start();
			}
			catch ( IOException e )
			{
				e.printStackTrace();
			}
		}
		
		return client;
	}
	
	private static void init()
	{
		fullScreen = false;
		vSync = true;
		
		LoginFrame lf = new LoginFrame();
		lf.showFrame();
	}
	
	private static void setUpDisplay()
	{
		try
		{
			if( !fullScreen )
			{
				Display.setDisplayMode( new DisplayMode( DISPLAY_WIDHT, DISPLAY_HEIGHT ) );
			}
			
			Display.setVSyncEnabled( vSync );
			Display.setFullscreen( fullScreen );
			Display.setTitle( GAME_NAME );
			Display.create();
		}
		catch( LWJGLException e )
		{
			System.err.println( "The display wasn't initialized correctly ..." );
			Display.destroy();
			System.exit( 1 );
		}
	}
	
	public static void startUp()
	{
		setUpDisplay();
		getClient();
		Game.getGame().start();
	}
}
